\doxysection{cr\+QUEUE\+\_\+\+RECEIVE }
\hypertarget{group__cr_q_u_e_u_e___r_e_c_e_i_v_e}{}\label{group__cr_q_u_e_u_e___r_e_c_e_i_v_e}\index{crQUEUE\_RECEIVE@{crQUEUE\_RECEIVE}}
croutine. h 
\begin{DoxyPre}
 crQUEUE\_RECEIVE(                     CoRoutineHandle\_t xHandle,                     QueueHandle\_t pxQueue,                     void *pvBuffer,                     TickType\_t xTicksToWait,                     BaseType\_t *pxResult                 )\end{DoxyPre}


The macro\textquotesingle{}s cr\+QUEUE\+\_\+\+SEND() and cr\+QUEUE\+\_\+\+RECEIVE() are the co-\/routine equivalent to the x\+Queue\+Send() and x\+Queue\+Receive() functions used by tasks.

cr\+QUEUE\+\_\+\+SEND and cr\+QUEUE\+\_\+\+RECEIVE can only be used from a co-\/routine whereas x\+Queue\+Send() and x\+Queue\+Receive() can only be used from tasks.

cr\+QUEUE\+\_\+\+RECEIVE can only be called from the co-\/routine function itself -\/ not from within a function called by the co-\/routine function. This is because co-\/routines do not maintain their own stack.

See the co-\/routine section of the WEB documentation for information on passing data between tasks and co-\/routines and between ISR\textquotesingle{}s and co-\/routines.


\begin{DoxyParams}{Parameters}
{\em x\+Handle} & The handle of the calling co-\/routine. This is the x\+Handle parameter of the co-\/routine function.\\
\hline
{\em px\+Queue} & The handle of the queue from which the data will be received. The handle is obtained as the return value when the queue is created using the x\+Queue\+Create() API function.\\
\hline
{\em pv\+Buffer} & The buffer into which the received item is to be copied. The number of bytes of each queued item is specified when the queue is created. This number of bytes is copied into pv\+Buffer.\\
\hline
{\em x\+Tick\+To\+Delay} & The number of ticks that the co-\/routine should block to wait for data to become available from the queue, should data not be available immediately. The actual amount of time this equates to is defined by config\+TICK\+\_\+\+RATE\+\_\+\+HZ (set in \doxylink{_free_r_t_o_s_config_8h_source}{Free\+RTOSConfig.\+h}). The constant port\+TICK\+\_\+\+PERIOD\+\_\+\+MS can be used to convert ticks to milliseconds (see the cr\+QUEUE\+\_\+\+SEND example).\\
\hline
{\em px\+Result} & The variable pointed to by px\+Result will be set to pd\+PASS if data was successfully retrieved from the queue, otherwise it will be set to an error code as defined within \doxylink{projdefs_8h_source}{Proj\+Defs.\+h}.\\
\hline
\end{DoxyParams}
Example usage\+: 
\begin{DoxyPre}
// A co-\/routine receives the number of an LED to flash from a queue.  It
// blocks on the queue until the number is received.
static void prvCoRoutineFlashWorkTask( CoRoutineHandle\_t xHandle, UBaseType\_t uxIndex )
\{
// Variables in co-\/routines must be declared static if they must maintain value across a blocking call.
static BaseType\_t xResult;
static UBaseType\_t uxLEDToFlash;

   // All co-\/routines must start with a call to crSTART().
   crSTART( xHandle );

   for( ;; )
   \{
       // Wait for data to become available on the queue.
       crQUEUE\_RECEIVE( xHandle, xCoRoutineQueue, \&uxLEDToFlash, portMAX\_DELAY, \&xResult );

       if( xResult == pdPASS )
       \{
           // We received the LED to flash -\/ flash it!
           vParTestToggleLED( uxLEDToFlash );
       \}
   \}

   crEND();
\}\end{DoxyPre}
 